package com.share.netty.im.server.handler;

import com.share.netty.im.request.MessageRequestPacket;
import com.share.netty.im.response.MessageResponsePacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Date;

/**
 * @author caifan
 * @createTime 2020/5/17
 * @desc: 服务端数据回写给客户端
 */
public class MessageRequestHandler extends SimpleChannelInboundHandler<MessageRequestPacket> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageRequestPacket msg) {
        MessageResponsePacket messageResponsePacket = new MessageResponsePacket();
        System.out.println(new Date() + ":client msg:" + msg.getMessage());
        messageResponsePacket.setMessage("server response :[" + msg.getMessage() + "]");

        ctx.channel().writeAndFlush(messageResponsePacket);
    }
}
